﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Validation</title>
  <keywords>
    <keyword translate="true">DataObjectBase</keyword>
    <keyword translate="true">Validation</keyword>
    <keyword translate="true">ViewModelBase</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Validation</text></para>
    </header>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_ViewModelBase" styleclass="Notes" translate="true">ViewModelBase</link><text styleclass="Notes" translate="true"> derives from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" style="font-style:italic;" translate="true">ModelBase</link><text styleclass="Notes" translate="true">, thus all information here also applies to the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_ViewModelBase" styleclass="Notes" translate="true">ViewModelBase</link></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Validation is very important for data objects. Therefore, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> supports all kinds of different validation:</text></para>
    <list id="2" type="ul" listtype="bullet" formatstring="&#183;" format-charset="SYMBOL_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Symbol; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="Validation_via_Validate_method" styleclass="Normal (list)" translate="true">Internal validation via the ValidateFields and ValidateBusinessRules methods</link></li>
      <li styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="Validation_via_Data_Annotation" styleclass="Normal (list)" translate="true">Validation via data annotations (attributes)</link></li>
      <li styleclass="Normal (list)"><link displaytype="text" defaultstyle="true" type="topiclink" href="Validation_via_IValidator" styleclass="Normal (list)" translate="true">External validators using the IValidatorProvider and IValidator interfaces</link></li>
    </list>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The validation results are cached and only executed when a property changes (the object becomes dirty) or when the validation is forced.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Different types of validation</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">There are two different types of validation in Catel, namely </text><text styleclass="Normal" style="font-style:italic;" translate="true">warnings</text><text styleclass="Normal" translate="true"> and </text><text styleclass="Normal" style="font-style:italic;" translate="true">errors</text><text styleclass="Normal" translate="true">. There are also two flavors of validations, namely </text><text styleclass="Normal" style="font-style:italic;" translate="true">field validation</text><text styleclass="Normal" style="font-style:normal;" translate="true"> and </text><text styleclass="Normal" style="font-style:italic;" translate="true">business rule</text><text styleclass="Normal" style="font-style:normal;" translate="true">&#32;</text><text styleclass="Normal" style="font-style:italic;" translate="true">validation</text><text styleclass="Normal" style="font-style:normal;" translate="true">.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Order of execution of events</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The order of execution is very important if you want to perform very advanced validation (such as translating validations at the end of each validation sequence). </text></para>
    <list id="3" type="ol" listtype="decimal" formatstring="&#37;&#48;&#58;&#115;&#46;" format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.BeforeValidation</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidation (raises Validating event)</text></li>
    </list>
    <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">if not already validated</text></para>
    <list id="3" type="ol" listtype="decimal" formatstring="&#37;&#48;&#58;&#115;&#46;" format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.BeforeValidateFields</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidatingFields (raises the ValidatingFields event)</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.ValidateFields</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">ValidateFields</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidatedFields (raises the ValidatedFields event)</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.AfterValidateFields</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.BeforeValidateBusinessRules</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidatingBusinessRules (raises the ValidatingBusinessRules event)</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.ValidateBusinessRules</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">ValidateBusinessRules</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidatedBusinessRules (raises the ValidatedBusinessRules event)</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.AfterValidateBusinessRules</text></li>
    </list>
    <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">end if not already validated</text></para>
    <list id="3" type="ol" listtype="decimal" formatstring="&#37;&#48;&#58;&#115;&#46;" format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">OnValidated (raises the Validated event)</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">IValidator.AfterValidation</text></li>
    </list>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:normal;" translate="true">There are lots of events, and it may seem complex and confusing at first sight. However, all these events give developers the opportunity to hook into the validation sequence at any time.</text></para>
  </body>
</topic>
